﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace RxjhServer
{
    public partial class SendItem : Form
    {
        private Players Player;


        public SendItem()
        {
            this.InitializeComponent();
        }

        public bool SetUser(string UserName)
        {
            this.Player = World.检查玩家name(UserName);
            if (this.Player != null)
            {
                return true;
            }
            return false;
        }

        public void SetUserName(string UserName)
        {
            //this.comboBox1.Text = UserName;
        }

        private void SendItem_Load(object sender, EventArgs e)
        {
            this.Player = null;
            this.textBox1.Text = "1";
            this.textBox6.Text = "0";
            this.textBox7.Text = "0";
            this.textBox8.Text = "0";
            this.textBox9.Text = "0";
            this.textBox10.Text = "0";
            //this.comboBox1.Text = "请选择";
            //foreach (Players current in World.allConnectedChars.Values)
            //{
            //    if (current != null)
            //    {
            //        this.comboBox1.Items.Add(current.UserName);
            //    }
            //}

        }
        private void comboBox11_SelectedIndexChanged(object sender, EventArgs e)
        {
            string reside2 = "";
            switch (comboBox11.Text)
            {
                case "武器": reside2 = "4"; break;
                case "衣服": reside2 = "1"; break;
                case "护手": reside2 = "2"; break;
                case "鞋子": reside2 = "5"; break;
                case "内甲": reside2 = "6"; break;
                case "项链": reside2 = "7"; break;
                case "耳环": reside2 = "8"; break;
                case "戒指": reside2 = "10"; break;
                case "披风": reside2 = "12"; break;
                case "弓箭": reside2 = "13"; break;
                case "门甲": reside2 = "14"; break;
                case "宝宝": reside2 = "15"; break;
                case "其他": reside2 = "0"; break;
                case "石头": reside2 = "16"; break;
            }
            listBox3.Items.Clear();
            //comboBox12.Items.Clear();
            //DataTable 物品信息 = SqlClass.Getpulicdb();
            //DbClss.DBA.ExeSqlCommand(sql, "PublicDb");
            string sql2 = string.Format("select * from TBL_物品列表 where FLD_RESIDE2='{0}'", reside2);
            System.Data.DataTable table1 = DbClss.DBA.GetDBToDataTable(sql2, "PublicDb");
            for (int i = 0; i < table1.Rows.Count; i++)
            {
                listBox3.Items.Add(table1.Rows[i]["FLD_NAME"].ToString());
                //comboBox12.Items.Add(table1.Rows[i]["FLD_PID"].ToString());
            }
            table1.Dispose();
        }
        private void listBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            string sql2 = string.Format("select * from TBL_物品列表 where FLD_NAME='{0}'", listBox3.SelectedItem);
            System.Data.DataTable table1 = DbClss.DBA.GetDBToDataTable(sql2, "PublicDb");

            textBox13.Text = table1.Rows[0]["FLD_PID"].ToString();
            table1.Dispose();

        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textBox2.Text))
            {
                 Player = World.检查玩家name(textBox2.Text);
                if (Player != null)
                {
                    int num = Player.得到包裹空位(Player);
                    if (num == -1)
                    {
                        MessageBox.Show("没有空位");
                        return;
                    }
                    this.Player.增加物品带属性(int.Parse(textBox13.Text), num, int.Parse(this.textBox1.Text), int.Parse(this.textBox6.Text), int.Parse(this.textBox7.Text), int.Parse(this.textBox8.Text), int.Parse(this.textBox9.Text), int.Parse(this.textBox10.Text), 0);
                    MessageBox.Show("发送成功，人物:" + this.Player.UserName + " 物品: " + listBox3.SelectedItem);
                }
                else
                {
                    MessageBox.Show("该玩家没有在线请重新输入");

                }
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //this.SetUser(this.comboBox1.SelectedItem.ToString());
        }



        private void button2_Click(object sender, EventArgs e)
        {
            //if (this.SetUser(this.comboBox1.Text))
            //{
            //    MessageBox.Show("查找完成");
            //    return;
            //}
            //MessageBox.Show("未找到此人物");
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textBox2.Text))
            {
                Player = World.检查玩家name(textBox2.Text);
                if (Player != null)
                {
                    //players.人物获得经验(num15 * (1.0 + players.人物_追加_经验百分比));
                    Player.Player_ExpErience += int.Parse(textBox3.Text);
                    //Player.人物获得金币((int)(num17 * (1.0 + players.人物_追加_金钱百分比)), 1);
                    //Player.得到钱的提示((uint)(num17 * (1.0 + players.人物_追加_金钱百分比)));
                    //Player.计算人物基本数据3();
                    Player.更新经验和历练();
                    Player.更新金钱和负重();
                    MessageBox.Show("发送成功，人物当前历练:" + Player.Player_ExpErience + " 增加历练: " + int.Parse(textBox3.Text));
                }
                else
                {
                    MessageBox.Show("该玩家没有在线请重新输入");
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textBox2.Text))
            {
                Player = World.检查玩家name(textBox2.Text);
                if (Player != null)
                {
                    Player.人物经验 += int.Parse(textBox4.Text);
                    //Player.Player_ExpErience += int.Parse(textBox3.Text);
                    //Player.人物获得金币((int)(num17 * (1.0 + players.人物_追加_金钱百分比)), 1);
                    //Player.得到钱的提示((uint)(num17 * (1.0 + players.人物_追加_金钱百分比)));
                    Player.计算人物基本数据3();
                    Player.更新经验和历练();
                    Player.更新金钱和负重();
                    MessageBox.Show("发送成功，人物当前经验:" + Player.人物经验 + " 增加经验: " + int.Parse(textBox4.Text));
                }
                else
                {
                    MessageBox.Show("该玩家没有在线请重新输入");
                }
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textBox2.Text))
            {
                Player = World.检查玩家name(textBox2.Text);
                if (Player != null)
                {
                    Player.Player_Level = int.Parse(textBox5.Text);

                    Player.人物经验=0;
                    //Player.Player_ExpErience += int.Parse(textBox3.Text);
                    //Player.人物获得金币((int)(num17 * (1.0 + players.人物_追加_金钱百分比)), 1);
                    //Player.得到钱的提示((uint)(num17 * (1.0 + players.人物_追加_金钱百分比)));
                    Player.计算人物基本数据3();
                    Player.更新经验和历练();
                    Player.更新金钱和负重();
                    MessageBox.Show("发送成功，当前等级:" + Player.Player_Level + " 增加等级: " + int.Parse(textBox5.Text));
                }
                else
                {
                    MessageBox.Show("该玩家没有在线请重新输入");
                }
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textBox2.Text))
            {
                Player = World.检查玩家name(textBox2.Text);
                if (Player != null)
                {
                    Player.Player_Money += int.Parse(textBox11.Text);

                    //Player.人物经验 = 0;
                    //Player.Player_ExpErience += int.Parse(textBox3.Text);
                    //Player.人物获得金币((int)(num17 * (1.0 + players.人物_追加_金钱百分比)), 1);
                    //Player.得到钱的提示((uint)(num17 * (1.0 + players.人物_追加_金钱百分比)));
                    //Player.计算人物基本数据3();
                    //Player.更新经验和历练();
                    Player.更新金钱和负重();
                    MessageBox.Show("发送成功，当前金币:" + Player.Player_Money + " 增加金币: " + int.Parse(textBox11.Text));
                }
                else
                {
                    MessageBox.Show("该玩家没有在线请重新输入");
                }
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {


            if (!string.IsNullOrEmpty(textBox2.Text))
            {

                Player = World.检查玩家name(textBox2.Text);
                if (Player != null)
                {
                    Player.查百宝阁元宝数();
                    Player.检察元宝数据(int.Parse(textBox12.Text), 1);
                    Player.保存元宝数据();
                    //Player.人物经验 = 0;
                    //Player.Player_ExpErience += int.Parse(textBox3.Text);
                    //Player.人物获得金币((int)(num17 * (1.0 + players.人物_追加_金钱百分比)), 1);
                    //Player.得到钱的提示((uint)(num17 * (1.0 + players.人物_追加_金钱百分比)));
                    //Player.计算人物基本数据3();
                    //Player.更新经验和历练();
                    MessageBox.Show("发送成功，当前元宝:" + Player.FLD_RXPIONT + " 增加元宝: " + int.Parse(textBox12.Text));
                }
                else
                {
                    MessageBox.Show("该玩家没有在线请重新输入");
                }
            }
        }
    }
}
